package com.neuedu.it.newidea.web;


import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

@CrossOrigin
@RestController
public class AiManageController {
    @Autowired
    @Qualifier("asistantClient")
    private ChatClient chatClient;

    @RequestMapping(value = "/ai/chat")
    public String chat(String question){
        String answer = chatClient.prompt()
                .user(question)
                .call()
                .content();
        return answer;
    }

    @GetMapping(value = "/ai/chat-stream",produces = "text/html;charset=UTF-8")
    public Flux<String> chatStream(@RequestParam String question) {
        return chatClient.prompt()
                    .user(question)
                    .stream()
                    .content();
    }
}
